﻿/**  PACS v1.0
* JC_CheckItem.cs
*
* 类 名： JC_CheckItem
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2018/6/5 15:24:26   douwd    初版
*
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Pacs.DAL
{
	/// <summary>
	/// 数据访问类:JC_CheckItem
	/// </summary>
	public partial class JC_CheckItem
	{
		public JC_CheckItem()
		{}
		#region  Method


		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from JC_CheckItem");
			strSql.Append(" where ID='"+ID+"' ");
			return DbHelperSQL.Exists(strSql.ToString());
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Pacs.Model.JC_CheckItem model)
		{
			StringBuilder strSql=new StringBuilder();
			StringBuilder strSql1=new StringBuilder();
			StringBuilder strSql2=new StringBuilder();
			if (model.ID != null)
			{
				strSql1.Append("ID,");
				strSql2.Append("'"+model.ID+"',");
			}
			if (model.XiangMuNO != null)
			{
				strSql1.Append("XiangMuNO,");
				strSql2.Append("'"+model.XiangMuNO+"',");
			}
			if (model.XiangMuMing != null)
			{
				strSql1.Append("XiangMuMing,");
				strSql2.Append("'"+model.XiangMuMing+"',");
			}
			if (model.JianChaBuWeiNO != null)
			{
				strSql1.Append("JianChaBuWeiNO,");
				strSql2.Append("'"+model.JianChaBuWeiNO+"',");
			}
			if (model.JianChaBuWeiID != null)
			{
				strSql1.Append("JianChaBuWeiID,");
				strSql2.Append("'"+model.JianChaBuWeiID+"',");
			}
			if (model.JianChaBuWeiMing != null)
			{
				strSql1.Append("JianChaBuWeiMing,");
				strSql2.Append("'"+model.JianChaBuWeiMing+"',");
			}
			if (model.SuoShujiGouNO != null)
			{
				strSql1.Append("SuoShujiGouNO,");
				strSql2.Append("'"+model.SuoShujiGouNO+"',");
			}
			if (model.JiGouID != null)
			{
				strSql1.Append("JiGouID,");
				strSql2.Append("'"+model.JiGouID+"',");
			}
			if (model.JianChaLeiXing != null)
			{
				strSql1.Append("JianChaLeiXing,");
				strSql2.Append("'"+model.JianChaLeiXing+"',");
			}
			if (model.JianChaLeiXingNO != null)
			{
				strSql1.Append("JianChaLeiXingNO,");
				strSql2.Append("'"+model.JianChaLeiXingNO+"',");
			}
			if (model.JianChaLeiXingID != null)
			{
				strSql1.Append("JianChaLeiXingID,");
				strSql2.Append("'"+model.JianChaLeiXingID+"',");
			}
			if (model.PinYinMa != null)
			{
				strSql1.Append("PinYinMa,");
				strSql2.Append("'"+model.PinYinMa+"',");
			}
			if (model.WuBiMa != null)
			{
				strSql1.Append("WuBiMa,");
				strSql2.Append("'"+model.WuBiMa+"',");
			}
			if (model.PaiXu != null)
			{
				strSql1.Append("PaiXu,");
				strSql2.Append(""+model.PaiXu+",");
			}
			strSql.Append("insert into JC_CheckItem(");
			strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
			strSql.Append(")");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Pacs.Model.JC_CheckItem model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update JC_CheckItem set ");
			if (model.XiangMuNO != null)
			{
				strSql.Append("XiangMuNO='"+model.XiangMuNO+"',");
			}
			else
			{
				strSql.Append("XiangMuNO= null ,");
			}
			if (model.XiangMuMing != null)
			{
				strSql.Append("XiangMuMing='"+model.XiangMuMing+"',");
			}
			else
			{
				strSql.Append("XiangMuMing= null ,");
			}
			if (model.JianChaBuWeiNO != null)
			{
				strSql.Append("JianChaBuWeiNO='"+model.JianChaBuWeiNO+"',");
			}
			else
			{
				strSql.Append("JianChaBuWeiNO= null ,");
			}
			if (model.JianChaBuWeiID != null)
			{
				strSql.Append("JianChaBuWeiID='"+model.JianChaBuWeiID+"',");
			}
			else
			{
				strSql.Append("JianChaBuWeiID= null ,");
			}
			if (model.JianChaBuWeiMing != null)
			{
				strSql.Append("JianChaBuWeiMing='"+model.JianChaBuWeiMing+"',");
			}
			else
			{
				strSql.Append("JianChaBuWeiMing= null ,");
			}
			if (model.SuoShujiGouNO != null)
			{
				strSql.Append("SuoShujiGouNO='"+model.SuoShujiGouNO+"',");
			}
			else
			{
				strSql.Append("SuoShujiGouNO= null ,");
			}
			if (model.JiGouID != null)
			{
				strSql.Append("JiGouID='"+model.JiGouID+"',");
			}
			else
			{
				strSql.Append("JiGouID= null ,");
			}
			if (model.JianChaLeiXing != null)
			{
				strSql.Append("JianChaLeiXing='"+model.JianChaLeiXing+"',");
			}
			else
			{
				strSql.Append("JianChaLeiXing= null ,");
			}
			if (model.JianChaLeiXingNO != null)
			{
				strSql.Append("JianChaLeiXingNO='"+model.JianChaLeiXingNO+"',");
			}
			else
			{
				strSql.Append("JianChaLeiXingNO= null ,");
			}
			if (model.JianChaLeiXingID != null)
			{
				strSql.Append("JianChaLeiXingID='"+model.JianChaLeiXingID+"',");
			}
			else
			{
				strSql.Append("JianChaLeiXingID= null ,");
			}
			if (model.PinYinMa != null)
			{
				strSql.Append("PinYinMa='"+model.PinYinMa+"',");
			}
			else
			{
				strSql.Append("PinYinMa= null ,");
			}
			if (model.WuBiMa != null)
			{
				strSql.Append("WuBiMa='"+model.WuBiMa+"',");
			}
			else
			{
				strSql.Append("WuBiMa= null ,");
			}
			if (model.PaiXu != null)
			{
				strSql.Append("PaiXu="+model.PaiXu+",");
			}
			else
			{
				strSql.Append("PaiXu= null ,");
			}
			int n = strSql.ToString().LastIndexOf(",");
			strSql.Remove(n, 1);
			strSql.Append(" where ID='"+ model.ID+"' ");
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from JC_CheckItem ");
			strSql.Append(" where ID='"+ID+"' " );
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from JC_CheckItem ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Pacs.Model.JC_CheckItem GetModel(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1  ");
			strSql.Append(" ID,XiangMuNO,XiangMuMing,JianChaBuWeiNO,JianChaBuWeiID,JianChaBuWeiMing,SuoShujiGouNO,JiGouID,JianChaLeiXing,JianChaLeiXingNO,JianChaLeiXingID,PinYinMa,WuBiMa,PaiXu ");
			strSql.Append(" from JC_CheckItem ");
			strSql.Append(" where ID='"+ID+"' " );
			Pacs.Model.JC_CheckItem model=new Pacs.Model.JC_CheckItem();
			DataSet ds=DbHelperSQL.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Pacs.Model.JC_CheckItem DataRowToModel(DataRow row)
		{
			Pacs.Model.JC_CheckItem model=new Pacs.Model.JC_CheckItem();
			if (row != null)
			{
				if(row["ID"]!=null)
				{
					model.ID=row["ID"].ToString();
				}
				if(row["XiangMuNO"]!=null)
				{
					model.XiangMuNO=row["XiangMuNO"].ToString();
				}
				if(row["XiangMuMing"]!=null)
				{
					model.XiangMuMing=row["XiangMuMing"].ToString();
				}
				if(row["JianChaBuWeiNO"]!=null)
				{
					model.JianChaBuWeiNO=row["JianChaBuWeiNO"].ToString();
				}
				if(row["JianChaBuWeiID"]!=null)
				{
					model.JianChaBuWeiID=row["JianChaBuWeiID"].ToString();
				}
				if(row["JianChaBuWeiMing"]!=null)
				{
					model.JianChaBuWeiMing=row["JianChaBuWeiMing"].ToString();
				}
				if(row["SuoShujiGouNO"]!=null)
				{
					model.SuoShujiGouNO=row["SuoShujiGouNO"].ToString();
				}
				if(row["JiGouID"]!=null)
				{
					model.JiGouID=row["JiGouID"].ToString();
				}
				if(row["JianChaLeiXing"]!=null)
				{
					model.JianChaLeiXing=row["JianChaLeiXing"].ToString();
				}
				if(row["JianChaLeiXingNO"]!=null)
				{
					model.JianChaLeiXingNO=row["JianChaLeiXingNO"].ToString();
				}
				if(row["JianChaLeiXingID"]!=null)
				{
					model.JianChaLeiXingID=row["JianChaLeiXingID"].ToString();
				}
				if(row["PinYinMa"]!=null)
				{
					model.PinYinMa=row["PinYinMa"].ToString();
				}
				if(row["WuBiMa"]!=null)
				{
					model.WuBiMa=row["WuBiMa"].ToString();
				}
				if(row["PaiXu"]!=null && row["PaiXu"].ToString()!="")
				{
					model.PaiXu=int.Parse(row["PaiXu"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,XiangMuNO,XiangMuMing,JianChaBuWeiNO,JianChaBuWeiID,JianChaBuWeiMing,SuoShujiGouNO,JiGouID,JianChaLeiXing,JianChaLeiXingNO,JianChaLeiXingID,PinYinMa,WuBiMa,PaiXu ");
			strSql.Append(" FROM JC_CheckItem ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,XiangMuNO,XiangMuMing,JianChaBuWeiNO,JianChaBuWeiID,JianChaBuWeiMing,SuoShujiGouNO,JiGouID,JianChaLeiXing,JianChaLeiXingNO,JianChaLeiXingID,PinYinMa,WuBiMa,PaiXu ");
			strSql.Append(" FROM JC_CheckItem ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM JC_CheckItem ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ID desc");
			}
			strSql.Append(")AS Row, T.*  from JC_CheckItem T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		*/

		#endregion  Method
		#region  MethodEx

		#endregion  MethodEx
	}
}

